
package com.zsrt.jmj.company.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zsrt.jmj.company.dao.CompanyDao;
import com.zsrt.jmj.company.entity.CompanyEntity;
import com.zsrt.jmj.company.service.CompanyService;

@Service
public class CompanyServiceImpl implements CompanyService {

	@Autowired
	private CompanyDao dao;
	@Transactional
	@Override
	public void add(CompanyEntity entity, Map<String, Object> map) {
		dao.insert(entity);
		map.put("result", "success");
		map.put("jieguo", "添加成功...");
	}

	@Transactional(readOnly=true)
	@Override
	public void findAllCompanys(Map<String, Object> map) {
		//List<CompanyEntity> list = dao.findAll();
		List<CompanyEntity> list = dao.selectAll();
		map.put("result", "success");
		map.put("jieguo", "查询成功...");
		map.put("data", list);
	}

	@Override
	public void updateById(CompanyEntity entity, Map<String, Object> map) {
		//dao.updateById(entity);
		dao.updateByPrimaryKey(entity);
		map.put("result", "success");
		map.put("jieguo", "修改成功...");
		
	}

	@Transactional(readOnly=true)
	@Override
	public void findCompanyById(int id, Map<String, Object> map) {
		//CompanyEntity entity = dao.findById(id);
		CompanyEntity entity = dao.selectByPrimaryKey(id);
		map.put("result", "success");
		map.put("jieguo", "查询成功...");
		map.put("data", entity);
		
	}

	@Transactional
	@Override
	public void deleteByIds(String ids, Map<String, Object> map) {
		String[] split = ids.split(",");
		List<Integer> idLists = new ArrayList<>(); 
		/*for(String s:split){
			int id = Integer.parseInt(s);
			dao.deleteById(id );
			
		}*/
		
		for(String s:split){
			int id = Integer.parseInt(s);
			idLists.add(id);
		}
		dao.deleteByIds(idLists);
		map.put("result", "success");
		map.put("jieguo", "成功...");
	}

}
